package Demo1;

public class T15 {
    private static  int n = 0;
    public static void main(String[] args) throws InterruptedException {

        /*              多线程
        * 每个线程循环 1w 次，累加变量 count 的值，count 默认值为 0，注意线程安全问题。*/
        Thread thread = new Thread(()->{
            for (int i = 1; i <= 10000; i++) {
                synchronized (T15.class){
                    n++;
                }
            }
        });
        Thread thread1 = new Thread(()->{
            for (int i = 1; i <= 10000; i++) {
                synchronized (T15.class){
                    n++;
                }
            }
        });
        thread1.start();
        thread.start();
        thread1.join();
        thread.join();
        System.out.println(n);
    }
}
